<?php
namespace Admin\Controller;
use Think\Controller;
class OrderdetailController extends Controller
{

	/**
	 * @var      String
	 */
	public $goodCount;

	/**
	 * @var      String
	 */
	public $pingJia;

	/**
	 * @var      String
	 */
	public $reply;

	/**
	 * @var      String
	 */
	public $pingJiaPlus;

	/**
	 * @return   void
	 */


	public function index()
	{
		// TODO: implement
		$where['xing']=I('get.xing','★★★★★');
		//获得数据
		$data = M('orderdetail')->where($where)->select();
		if(IS_POST){
			$id=I('post.search',0,'int');
			if($id!=0){
				$iwhere="order_OrderId=$id or goods_GoodId=$id";
				$data = M('orderdetail')->where($iwhere)->select();
			}
		}
		//视图
		$this->assign("data",$data);
		$this->assign("xing",$where['xing']);
		$this->display();
	}



	public function addPingJia()
	{
		// TODO: implement
	}

	/**
	 * @return   void
	 */
	public function pingJiaPlus()
	{
		// TODO: implement
	}

	/**
	 * @return   void
	 */
	public function deletePingJia()
	{
		// TODO: implement
	}

	/**
	 * @return   array
	 */
	public function checkPingJia()
	{
		// TODO: implement
		$subwherex=explode('@@@', $_GET['orderdetail']);
		$subwhere['order_OrderId']=$subwherex[0];
		$subwhere['goods_GoodId']=$subwherex[1];
		$subwhere['goods_Color']=$subwherex[2];
		$subwhere['goods_Version']=$subwherex[3];
		if(IS_POST){
			$this->replyPingJia($subwhere);
		}
		$data=M('orderdetail')->where($subwhere)->find();


		$userid=M('order')->where("OrderId=$subwherex[0]")->getField('UserId');
		$username=M('user')->where("UserId=$userid")->getField('UserName');
		$this->assign("orderdetail",$_GET['orderdetail']);
		$this->assign("userid",$userid);
		$this->assign("username",$username);
		$this->assign($data);
		$this->display('reply');
	}

	/**
	 * @return   void
	 */
	public function replyPingJia($subwhere)
	{
		// TODO: implement
		$data['Reply']=$_POST['Reply'];
		$rst=M('orderdetail')->where($subwhere)->save($data);
		if($rst==false){
			$this->error("回复评论失败！");
		}
		echo "<script language='javascript' type='text/javascript'>alert('回复评论成功！')</script>";
			$url = __CONTROLLER__."/index";
			echo "<script language='javascript' type='text/javascript'>window.location.href='$url'</script>";
			return;
	}
}

?>